package com.epam.xml.xmlimport;

import java.io.IOException;
import java.util.List;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.apache.log4j.Logger;
import org.apache.log4j.chainsaw.Main;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;

import com.epam.xml.bank.Client;

public class DomParserLauncher {
	private static Logger logger = Logger.getLogger(DomParserLauncher.class);

	public static void main(String[] args) {
		try {
			DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
			DocumentBuilder db = dbf.newDocumentBuilder();
			Document document = db.parse(Main.class.getClassLoader()
					.getResource("Clients.xml").getFile());
			Element root = document.getDocumentElement();
			DOMParser parser = new DOMParser();
			List<Client> clients = parser.parse(root);
			for (Client cl:clients) {
				logger.info(cl.toString());
			}
		} catch (ParserConfigurationException e) {
			logger.error(e);
		} catch (SAXException e1) {
			logger.error(e1);
		} catch (IOException e2) {
			logger.error(e2);
		}

	}

}
